"use strict"
 1.
 function indexOf(arr,item){
    for(var i=0;i<arr.length;i++){
        if( item !==arr[i] ){
             return -1;
        }
        else {
            return i;
        }
    }
 }
 

 2.
 function sum(arr){
     var summ=0;
      for(var i=0;i<arr.length;i++){
           summ= summ+arr[i];
      }
 }

 3.
 function remove(arr,item) {
    var a=arr.slice(0);
    for(var i=0;i<arr.length;i++){
      if(a[i]==item){
        a.splice(i,1);
        i--;
      }
    }
    return a;
};


 4.
 function removeWithoutCopy(arr, item) {
    for(var i=0;i<arr.length;i++){
        if(arr[i]==item){
            arr.splice(i,1);
            i--;
        }
    }
    return arr;
 
}
5.
 function  append(arr,item){
       return arr.push(item);
 }
   

 6.
 function truncate(arr,item){
        return arr.pop(item);
 }
7.
  function  prepend(arr,item) {
    return arr.unshift(item);
  }

 8.
 function curtail(arr){
       return arr.shift();
 }


 9.
 function concat(arr1,arr2){
     return arr1.join(arr2);
 }

  10.
 function insert(arr,item,index){
       return  arr.splice(index,0,item);
 }

11.
function count(arr, item) {
    var s = 0;
    for(var i = 0; i<arr.length; i++){
        if(arr[i] == item){
            s++;  
        }    
    }
    return s;    
}
12.
function duplicates(arr) {
    var result = [];
    arr.forEach(function(item){
        if(arr.indexOf(item)!=arr.lastIndexOf(item)&&result.indexOf(item)==-1)
            result.push(item);
    })
    return result;
}
    
13.
function square(arr) {
    var arr_new = [];
    for(var i = 0;i < arr.length;i++){
        arr_new[i] = arr[i]*arr[i];
    }
    return arr_new;		
}
var arr = [1, 2, 3, 4];
document.write(square(arr));
14.
function findAllOccurrences(arr, target) {
    var arr1=[];
    var j=0;
    for(var i=0;i<arr.length;i++){
        if(arr[i]===target){
            arr1.push(arr.indexOf(arr[i],j));
            j++;
        }
    }
    return arr1;
}
15.

function identity(val1,val2){
  if (val1===val2){
         console.log( "完全相等");
  }else
  {
      console.log( "不完全相等");
  }
}
16.

17.
var test=document.getElementById("test-list") 


var 
    form = $('#test-form'),
    langs = form.find('[name=lang]'),
    selectAll = form.find('label.selectAll :checkbox'),
    selectAllLabel = form.find('label.selectAll span.selectAll'),
    deselectAllLabel = form.find('label.selectAll span.deselectAll'),
    invertSelect = form.find('a.invertSelect');

// 重置初始化状态:
form.find('*').show().off();
form.find(':checkbox').prop('checked', false).off();
deselectAllLabel.hide();
// 拦截form提交事件:
form.off().submit(function (e) {
    e.preventDefault();
    alert(form.serialize());
});
// TODO:绑定事件
selectAll.hide();
selectAllLabel.css('color','blue');
deselectAllLabel.css('color','blue');
selectAllLabel.click(function () {
    if (selectAll.prop('checked')) {
        langs.prop('checked', true);
        selectAllLabel.hide();
        deselectAllLabel.show();
    }
})

deselectAllLabel.click(function () {
    langs.prop('checked', false);
    deselectAllLabel.hide();
    selectAllLabel.show();
})

invertSelect.click(function () {
    langs.map(function () {
        $(this).prop('checked', !$(this).prop('checked'));
    })
})
langs.map(function () {
    $(this).change(function () {
        if ($('[name=lang]:checked').length === 5) {
            selectAll.prop('checked', true);
            selectAllLabel.hide();
            deselectAllLabel.show();
        } else {
            selectAll.prop('checked',false);
            deselectAllLabel.hide();
            selectAllLabel.show();
        }
    })
})

